package island.gotenyama.wand.web;

import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;

/**
 * 本システム向けVelocityビューリゾルバ
 * 
 * @author tk
 */
public class AppsVelocityViewResolver extends VelocityViewResolver {

	/**
	 * レイアウトＵＲＬ
	 */
	private String layoutUrl;

	/**
	 * レイアウトキー
	 */
	private String layoutKey;

	/**
	 * メインコンテンツのキー値
	 */
	private String screenContentKey;
	
	/**
	 * デリゲート
	 */
	private ViewDelegate viewDelegate;

	@Override
	protected Class<AppsVelocityView> requiredViewClass() {
		return AppsVelocityView.class;
	}

	public void setLayoutUrl(String layoutUrl) {
		this.layoutUrl = layoutUrl;
	}

	public void setLayoutKey(String layoutKey) {
		this.layoutKey = layoutKey;
	}

	public void setScreenContentKey(String screenContentKey) {
		this.screenContentKey = screenContentKey;
	}
	
	public ViewDelegate getViewDelegate() {
		return viewDelegate;
	}

	public void setViewDelegate(ViewDelegate viewDelegate) {
		this.viewDelegate = viewDelegate;
	}

	@Override
	protected AbstractUrlBasedView buildView(String viewName) throws Exception {
		AppsVelocityView view = (AppsVelocityView) super.buildView(viewName);
		if (this.layoutUrl != null) {
			view.setLayoutUrl(this.layoutUrl);
		}
		if (this.layoutKey != null) {
			view.setLayoutKey(this.layoutKey);
		}
		if (this.screenContentKey != null) {
			view.setScreenContentKey(this.screenContentKey);
		}
		return view;
	}
}
